import Vue from 'vue'
import VueRouter from 'vue-router'
import HomeView from '../views/HomeView.vue'
import Index from '../views/Index.vue'

Vue.use(VueRouter)

const routes = [{
    path: '/airpodsPro', //张峰伟
    name: 'airpodsPro',
    component: () => import('../views/AirpodsPro.vue'),
    meta: {
      title: '苹果airpodsPro页面'
    },
  },
  {
    path: '/watch3', //张峰伟
    name: 'watch3',
    component: () => import('../views/Watch3.vue'),
    meta: {
      title: '苹果watch3页面'
    },
  },
  {
    path: '/airPodsMax', //于孙虎
    name: 'airPodsMax',
    component: () => import('../views/AirpodsMax.vue'),
    meta: {
      title: '苹果airPodsMax页面'
    },
  },
  {
    path: '/airPods3', //于孙虎
    name: 'airPods3',
    component: () => import('../views/AirPods3.vue'),
    meta: {
      title: '苹果airPods3页面'
    },
  },
  {
    path: '/airPods2', //于孙虎
    name: 'airPods2',
    component: () => import('../views/AirPods2.vue'),
    meta: {
      title: '苹果airPods2页面'
    },
  },
  {
    path: '/watchSE', //沈长昊
    name: 'watchSE',
    component: () => import('../views/watchSE.vue'),
    meta: {
      title: '苹果watchSE页面'
    },
  },
  {
    path: '/watchS7', //沈长昊
    name: 'watchS7',
    component: () => import('../views/WatchS7.vue'),
    meta: {
      title: '苹果watchS7页面'
    },
  },
  {
    path: '/AirtagH', //胡云龙
    name: 'AirtagH',
    component: () => import('../views/AirtagH.vue'),
    meta: {
      title: '苹果AirtagH页面'
    },
  },
  {
    path: '/byAirtag', //胡云龙
    name: 'byAirtag',
    component: () => import('../views/ByAirtag.vue'),
    meta: {
      title: '苹果By-airtag页面'
    },
  },
  {
    path: '/homepodMini', //胡云龙
    name: 'homepodmini',
    component: () => import('../views/HomepodMini.vue'),
    meta: {
      title: '苹果homepodMini页面'
    },
  },
  {
    path: '/ipadMini', //杨一婷
    name: 'ipadmini',
    component: () => import('../views/IpadMini.vue'),
    meta: {
      title: '苹果ipad-Mini'
    },
  },
  {
    path: '/ipad10-2', //杨一婷
    name: 'ipad10-2',
    component: () => import('../views/Ipad10-2.vue'),
    meta: {
      title: '苹果ipad-10-2'
    },
  },
  {
    path: '/ipadAir', //杨一婷
    name: 'ipadAir',
    component: () => import('../views/IpadAir.vue'),
    meta: {
      title: '苹果ipadAir'
    },
  },
  {
    path: '/ipadPro', //杨一婷
    name: 'ipadPro',
    component: () => import('../views/IpadPro.vue'),
    meta: {
      title: '苹果ipadPro'
    },
  },
  {
    path: '/iphoneSE', //王张
    name: 'iphoneSE',
    component: () => import('../views/Iphone-se.vue'),
    meta: {
      title: '苹果iphone-se'
    },
  },
  {
    path: '/iphone12', //王张
    name: 'iphone12',
    component: () => import('../views/Iphone-12.vue'),
    meta: {
      title: '苹果iphone12'
    },
  },
  {
    path: '/iphone13pro', //王张
    name: 'iphone13pro',
    component: () => import('../views/Iphone-13pro.vue'),
    meta: {
      title: '苹果iphone13pro'
    },
  },
  {
    path: '/iphone13', //王张
    name: 'iphone13',
    component: () => import('../views/Iphone-13.vue'),
    meta: {
      title: '苹果iphone13'
    },
  },
  {
    path: '/imac', //石磊锋
    name: 'imac',
    component: () => import('../views/Imac.vue'),
    meta: {
      title: '苹果imac'
    },
  },
  {
    path: '/macpro-14', //石磊锋
    name: 'macpro-14',
    component: () => import('../views/MacPro-14.vue'),
    meta: {
      title: '苹果macPro-14'
    },
  },
  {
    path: '/macpro-13', //石磊锋
    name: 'macpro-13',
    component: () => import('../views/MacPro-13.vue'),
    meta: {
      title: '苹果macPro-13'
    },
  },
  {
    path: '/macbookAir-M2', //石磊锋
    name: 'macbookAir-M2',
    component: () => import('../views/MacAir-M2.vue'),
    meta: {
      title: '苹果macAir-M2'
    },
  },
  {
    path: '/macbookAir-M1', //石磊锋
    name: 'macbookAir-M1',
    component: () => import('../views/MacAir-M1.vue'),
    meta: {
      title: '苹果macAir-M1'
    },
  },
  {
    path: '/shoplist', //胡云龙产品列表
    name: 'shoplist',
    component: () => import('../views/ShopList.vue'),
    meta: {
      title: '苹果商店-商品列表',
      keepAlive:true,
    },
  },
  {
    path: '/backToSchool', //张峰伟教育优惠页面
    name: 'backToSchool',
    component: () => import('../views/BackToSchool.vue'),
    meta: {
      title: '苹果官网首页-教育优惠'
    },
  },
  {
    path: '/register', //新组员注册页面
    name: 'register',
    component: () => import('../views/Register.vue'),
    meta: {
      title: '苹果注册页面'
    },
  },
  {
    path: '/login', //新组员登录页面
    name: 'login',
    component: () => import('../views/Login.vue'),
    meta: {
      title: '苹果登陆页面'
    },
  },

  {
    path: '/parts', //配件于孙虎页面
    name: 'parts',
    component: () => import('../views/Parts.vue'),
    meta: {
      title: '苹果商店-配件'
    },
  },
  {
    path: '/airtag', //胡云龙airtag页面
    name: 'airtag',
    component: () => import('../views/AirTag.vue'),
    meta: {
      title: '苹果商店-airtag'
    },
  },
  {
    path: '/family', //胡云龙家居页面
    name: 'family',
    component: () => import('../views/Family.vue'),
    meta: {
      title: '苹果商店-家居'
    },
  },
  {
    path: '/airpods', //于孙虎airpods页面
    name: 'airpods',
    component: () => import('../views/Airpods.vue'),
    meta: {
      title: '苹果商店-airpods'
    },
  },
  {
    path: '/support', //沈长昊技术支持页面
    name: 'support',
    component: () => import('../views/Support.vue'),
    meta: {
      title: '苹果商店-技术支持'
    },
  },
  {
    path: '/watch', //沈长昊watch页面
    name: 'watch',
    component: () => import('../views/Watch.vue'),
    meta: {
      title: '苹果商店-watch'
    },
  },
  {
    path: '/iphone', //王张iphone页面
    name: 'iphone',
    component: () => import('../views/Iphone.vue'),
    meta: {
      title: '苹果商店-iphone'
    },
  },
  {
    path: '/ipad', //杨一婷ipad页面
    name: 'ipad',
    component: () => import('../views/Ipad.vue'),
    meta: {
      title: '苹果商店-ipad'
    },
  },
  {
    path: '/mac', //石磊峰mac页面
    name: 'mac',
    component: () => import('../views/Mac.vue'),
    meta: {
      title: '苹果商店-mac'
    },
  },
  {
    path: '/store', //张峰伟商店首页
    name: 'store',
    component: () => import('../views/Store.vue'),
    meta: {
      title: '苹果商店-首页'
    },
  },
  {
    path: '/', //杨一婷苹果官网首页
    name: 'index',
    component: Index,
    meta: {
      title: '苹果官网-首页'
    },
  },
  {
    path: '/home',
    name: 'home',
    component: HomeView
  },  
  {
    path: '/shoppingcart', //宋隆购物车页面
    name: 'shoppingcart',
    component: () => import('../views/ShoppingCart.vue'),
    meta: {
      title: '用户购物车'
    },
  },
  {
    path: '/successTopay', //购买成功后跳转的页面
    name: 'successTopay',
    component: () => import('../views/successToPay.vue'),
    meta: {
      title: '购买成功'
    },
  },
  {
    path: '/testing_ipadpro',
    name: "ipadpro测试页面",
    component: () => import('../views/testing/IpadProT.vue'),
  },
  {
    path: '/macT',
    name: "mac的数据测试页面",
    component: () => import('../views/testing/macT.vue'),
  },
  {
    path: '/about',
    name: 'about',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import( /* webpackChunkName: "about" */ '../views/AboutView.vue')
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes,
  //延迟滚动有时候，我们需要在页面中滚动之前稍作等待。例如，当处理过渡时，我们希望等待过渡结束后再滚动。要做到这一点，你可以返回一个 Promise，它可以返回所需的位置描述符。下面是一个例子，我们在滚动前等待 100ms：
  //我们可以将其与页面级过渡组件的事件挂钩，以使滚动行为与你的页面过渡很好地结合起来，但由于使用场景可能存在的差异和复杂性，我们只是提供了这个基础来实现特定的用户场景。
  scrollBehavior(to, from, savedPosition) {
    return new Promise((resolve, reject) => {
      setTimeout(() => {
        if (savedPosition) {
          resolve(savedPosition)
        } else {
          resolve({
            x: 0,
            y: 0
          })
        }
      }, 100)
    })
  }
})

router.beforeEach((to, from, next) => {
  //修改标题
  document.title = to.meta.title
  //next:调用后 才能允许本次跳转,不调用不放行
  next()
})

export default router